package org.igeek.atomqq.adapter;

import org.igeek.atomqq.AtomQQApplication;
import org.igeek.atomqq.activity.BaseActivity;
import org.igeek.atomqq.domain.Group;
import org.igeek.atomqq.widget.GroupItemView;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/** 
 * 好友分组适配器 
 * @author <a href="http://hangxin1940.cnblogs.com">hangxin1940@gmail.com</a>
 * @time 2012-2-2 下午05:27:30 
 */
public class GroupListAdapter extends BaseAdapter{

	private AtomQQApplication application;
	private BaseActivity context;
	
	public GroupListAdapter(BaseActivity context) {
		application=(AtomQQApplication) context.getApplication();
		this.context=context;
	}
	

	@Override
	public int getCount() {
		return application.getGroupCount();
	}



	@Override
	public Object getItem(int position) {
		return application.getGroup(position);
	}



	@Override
	public long getItemId(int position) {
		return application.getGroup(position).getGid();
	}



	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		Group group=application.getGroup(position);
		
		if(null==convertView){
			GroupViewHolder holder=new GroupViewHolder(context);
			holder.groupView.setGroup(group);
			return holder.groupView;
		}
		
		((GroupItemView)convertView).setGroup(group);
		
		return convertView;
	}
	
	
	
	static class GroupViewHolder{
		static GroupItemView groupView;
		public GroupViewHolder(BaseActivity context) {
			groupView=new GroupItemView(context);
		}
	}



}
